package com.zxy.study.base.recyclerview;


import java.util.ArrayList;
import java.util.List;



/**
 * Created by wensefu on 2017/7/17.
 */

public class RecyclerData<T> {

    public static final int TYPE_DEFAULT = 1;

    private T data;
    private int type;
    private boolean sel;

    public RecyclerData(int type,T data) {
        this.data = data;
        this.type = type;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean isSel() {
        return sel;
    }

    public void setSel(boolean sel) {
        this.sel = sel;
    }

    public static <K> List<RecyclerData> fromDataList(List<K> datalist) {
        return fromDataList(datalist,TYPE_DEFAULT);
    }

    @SuppressWarnings("unchecked")
    public static <K> List<RecyclerData> fromDataList(List<K> datalist, int type) {
        List<RecyclerData> result = new ArrayList<>();

        if(datalist != null && datalist.size() > 0){
            for (K k : datalist) {
                result.add(new RecyclerData<>(type,k));
            }
        }

        return result;
    }

    public static <K> RecyclerData fromData(K data,int type){
        return new RecyclerData<>(type,data);
    }

    public static <K> RecyclerData fromData(K data){
        return fromData(data,TYPE_DEFAULT);
    }
}
